package cn.com.sparknet.jsindustrymanager.webservice;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

public class DeviceRegService
{

    public static final String NAMESPACE   = "http://services.sparknet.com.cn";
    public static final String SERVICEPATH = "DeviceReg/services/DeviceRegService";

    private String             serviceUrl  = null;

    public DeviceRegService(String serviceHost)
    {
        if (serviceHost == null)
            throw new NullPointerException();
        if (!serviceHost.endsWith("/"))
            serviceHost = serviceHost + "/";
        this.serviceUrl = serviceHost + SERVICEPATH;
    }

    public int submitRegistry(String IMEI, String deviceId, String phoneNumber, String IMSI) throws XmlPullParserException, IOException
    {
        SoapObject request = new SoapObject(NAMESPACE, "submitRegistry");
        request.addProperty("IMEI", IMEI);
        request.addProperty("deviceId", deviceId);
        request.addProperty("phoneNumber", phoneNumber);
        request.addProperty("IMSI", IMSI);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = request;
        // envelope.setOutputSoapObject(request);
        // (new MarshalBase64()).register(envelope);
        HttpTransportSE ht = new HttpTransportSE(serviceUrl);
        // ht.debug = true;
        ht.call(null, envelope);
        return (Integer) envelope.getResponse();
    }

}
